<@override name="link">
</@override>
<@override name="body">
<body class="gray-bg">
<div class="col-sm-12">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <form action="submit" method="post" class="form-horizontal">
                <div class="form-group">
                    <label for="name" class="col-xs-3 control-label">
                        名称
                    </label>
                    <div class="col-xs-8">
                        <input type="text" id="name" name="name" class="form-control"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</@override>
<@override name="script">
<script type="text/javascript" src="${base}/resources/admin/js/ueditor/dialogs/internal.js"></script>
<script type="text/javascript">
    var oNode = null, thePlugins = 'canvas';
    /* Thank you by
      http://www.alt-tag.com/blog/2006/02/ie-dom-bugs/ */
    var num=0

    function createElement(type, name) {
        var element = null;
        try {
            element = document.createElement('<' + type + ' name="' + name + '">');
        } catch (e) {
        }
        if (element == null) {
            element = document.createElement(type);
            element.name = name;
        }
        return element;
    }

    window.onload = function () {
        if (UE.plugins[thePlugins].editdom) {
            oNode = UE.plugins[thePlugins].editdom;
        }
    }
    dialog.oncancel = function () {
        if (UE.plugins[thePlugins].editdom) {
            delete UE.plugins[thePlugins].editdom;
        }
    };

    function radio(obj) {
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                // alert(obj[i].value);
                return obj[i].value;
            }
        }

    }

    dialog.onok = function () {
        $('form').validate({
            rules: {
                name: {
                    required: true
                }
            },
            messages: {
                name: {
                    required: "必填"
                }
            },
            submitHandler: function (form) {
                try {
                    var params = {};
                    params.name = $('#name').val();
                    params.inputValue = "手写板";
                    params.dbType = 2;
                    params.typeId = '${typeId}';
                    params.fileType = "${type}";
                    params.inputValueNum = '542';
                    params.w = '220';
                    params.h = '35';
                    params.magnificent = '4';
                    params = JSON.stringify(params);
                    $.ajax({
                        type: "post",
                        url: "../form/submit",
                        data: {"params": params},
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                data = data.data;
                                console.log(data);
                                oNode = createElement('input', 'leipiNewField');
                                oNode.setAttribute('type', 'button');
                                oNode.setAttribute('title', $("#name").val());
                                oNode.setAttribute('value', "手写版");
                                oNode.setAttribute('name', data.inputName);
                                oNode.setAttribute('tplid', data.typeId);
                                oNode.setAttribute('tpltype', data.inputType);
                                oNode.setAttribute('leipiPlugins', thePlugins);
                                oNode.setAttribute('fromid', data.id);
                                oNode.setAttribute('style', 'width:80px;height:25px; border:#46b8da solid 1px; background-color:#46b8da;color:#FFF; font-size:12px; line-height:25px;border-radius:5px;');
                                oNode.setAttribute('class', 'btn btn-info');
                                oNode.setAttribute('id', 'canvas');
                                editor.execCommand('insertHtml', oNode.outerHTML, true);
                                dialog.close(false);
                            }
                            Common.alert(data);
                        }, error: function (error) {
                            console.log(error);
                        }
                    })
                } catch (e) {
                    editor.execCommand('error');
                    return false;
                }
            }
        });
        $('form').submit();
        return false;

    }
    /* if($G('fromname').value==''){
         alert('请输入控件名称');
         return false;
     }
     var fromname=$G('fromname').value.replace(/\"/g,"&quot;");
     if( !oNode ) {
         try {
             jQuery.ajax({
                 type: 'GET',
                 url: 'admin.php?ac=tplhtml&fileurl=apps&tplid=<?php echo $tplid;?>&tpltype=<?php echo $tpltype;?>&fromid=<?php echo $fromid;?>&do=addsave&type=canvas&fromname='+encodeURI(fromname)+'&dbtype=1&inputvalue=手写板&confirmation=2&w=80&h=25&date='+new Date(),
                 success: function(data){
                     if(data!=''){
                         //alert(data);
                     }
                 }
             });
             //添加控件执行块
                 oNode = createElement('input','leipiNewField');
                 oNode.setAttribute('type','button');
                 oNode.setAttribute('title',fromname);
                 oNode.setAttribute('value',"手写版");
                 oNode.setAttribute('name','<?php echo $row['inputname'];?>');
                 oNode.setAttribute('tplid','<?php echo $tplid;?>');
                 oNode.setAttribute('tpltype','<?php echo $tpltype;?>');
                 oNode.setAttribute('leipiPlugins',thePlugins);
                 oNode.setAttribute('fromid',<?php echo $row['fromid'];?>);
                 oNode.setAttribute('style','width:80px;height:25px; border:#46b8da solid 1px; background-color:#46b8da;color:#FFF; font-size:12px; line-height:25px;border-radius:5px;');
                 oNode.setAttribute('class','btn btn-info');
                 oNode.setAttribute('id','canvas');
                 editor.execCommand('insertHtml',oNode.outerHTML);
         } catch (e) {
             try {
                 editor.execCommand('error');
             } catch ( e ) {
                 alert('控件异常！');
             }
             return false;
         }
     } else {
         //修改控件执行块
         jQuery.ajax({
             type: 'GET',
             url: 'admin.php?ac=tplhtml&fileurl=apps&tplid=<?php echo $tplid;?>&tpltype=<?php echo $tpltype;?>&fromid=<?php echo $fromid;?>&do=addsave&type=text&fromname='+encodeURI(fromname)+'&dbtype=1&inputvalue='+encodeURI('手写版')+'&confirmation='+confirmation+'&w='+w+'&h='+h+'&date='+new Date(),
             success: function(data){
                 if(data!=''){
                     //alert(data);
                 }
             }
         });
         oNode.setAttribute('type','text');
         oNode.setAttribute('title',fromname);
         oNode.setAttribute('value','手写板');
         oNode.setAttribute('name','<?php echo $row['inputname'];?>');
         oNode.setAttribute('tplid','<?php echo $tplid;?>');
         oNode.setAttribute('tpltype','<?php echo $tpltype;?>');
         oNode.setAttribute('leipiPlugins',thePlugins);
         oNode.setAttribute('fromid',<?php echo $row['fromid'];?>);
         if(w!='' && h!=''){
             oNode.setAttribute('style','width:'+w+'px;height:'+h+'px;');
         }
         delete UE.plugins[thePlugins].editdom;
     }
 };*/
</script>
</@override>
<@extends name="../base/main.html"/>